﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FrbaBus.Core;
using System.Data.SqlClient;
using System.Text.RegularExpressions;


namespace FrbaBus.Compra_de_Pasajes
{
    public partial class SeleccionarEncomiendas : Form
    {
        public SeleccionarEncomiendas()
        {
            InitializeComponent();
        }
        private CompraPasajes parent = null;
        public DataGridViewRow Row;
        public SeleccionarEncomiendas (Form callingForm)
        {
            parent = callingForm as CompraPasajes;

            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Compra_de_Pasajes.Cliente frm = new Compra_de_Pasajes.Cliente(this);
            frm.ShowDialog(this);

            //this.Close();
        }
        private void textchanged(object sender, KeyPressEventArgs e)
        {
            int i = e.KeyChar;
            if (i >= 48 && i <= 57 || i == 8 || i == 13)
            {
            }
            else
            {
                MessageBox.Show("Solo están permitidos caracteres numéricos.");
                e.Handled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Debe ingresar un numero de DNI.");
            }
            else
            {
                int cantidad = 0;
                if (parent.dataGridView3.Rows.Count <= 0)
                    cantidad = 0;
                else
                    cantidad = parent.dataGridView3.Rows.Count;

                parent.dataGridView3.Rows.Add(1);
                parent.dataGridView3.Rows[cantidad].Cells[0].Value = string.Copy(textBox1.Text);
                parent.dataGridView3.Rows[cantidad].Cells[2].Value = string.Copy(numericUpDown1.Value.ToString());
                double precio = Convert.ToDouble(parent.dataGridView2.SelectedCells[8].Value.ToString());
                int kg = int.Parse(numericUpDown1.Value.ToString());
                double total = precio * kg;
                parent.dataGridView3.Rows[cantidad].Cells[1].Value = string.Copy(total.ToString());

                this.Close();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SeleccionarEncomiendas_Load(object sender, EventArgs e)
        {
            numericUpDown1.Maximum = Convert.ToDecimal(parent.dataGridView2.SelectedCells[6].Value.ToString());
            if (numericUpDown1.Value.ToString() == "0")
            {
                MessageBox.Show("El micro ya no posee Kg disponibles para encomiendas.");
                this.Close();
            }
        }
    }
}
